home *** CD-ROM | disk | FTP | other *** search
-
- /* Operators for functional programming.
- * Examples:
- * a:b:c:{} -> {a,b,c}
- * "Sin" @ a -> Sin(a)
- * "Sin" @ {a,b} -> Sin(a,b)
- * "Sin" /@ {a,b} -> {Sin(a),Sin(b)}
- * 1 .. 4 -> {1,2,3,4}
- */
-
-
- RuleBase(":",{head,tail});
- Rule(":",2,1,IsList(tail) ) Concat({head},tail);
- Rule(":",2,1,IsString(tail)) ConcatStrings(head,tail);
- UnFence(":",2);
-
-
- RuleBase("@",{func,arg});
- Rule("@",2,1,IsList(arg)) Apply(func,arg);
- Rule("@",2,2,True ) Apply(func,{arg});
-
- Function("/@",{func,lst}) Apply("MapSingle",{func,lst});
-
- Function("..",{from,to}) Table(i,i,from,to,1);
-
-
- /* NFunction("new'func", "old'func" {arg'list}) will define a wrapper function
- around "old'func", called "new'func", which will return "old'func(arg'list)"
- only when all arguments are numbers and will return unevaluated
- "new'func(arg'list)" otherwise. */
-
- NFunction(new'name_IsString, old'name_IsString, arg'list_IsList) <-- [
- MacroRuleBase(new'name, arg'list);
- MacroRule(new'name, Length(arg'list), 0, // check whether all args are numeric
- UnList({IsNumericList, arg'list})
- )
- UnList({Atom("@"), old'name, arg'list}); // cannot use '@' b/c get a syntax error
- ];
-